package com.sicau.controller;

import com.sicau.agent.Manus;
import com.sicau.app.PsychologicalConsultationApp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import reactor.core.publisher.Flux;

@Tag(name = "AiChatController", description = "ai相关控制器")
@RestController
@RequestMapping("/ai")
public class AiChatController {

    @Resource
    private PsychologicalConsultationApp psychologicalConsultationApp;
    @Resource
    private ChatModel chatModel;
    @Resource
    private ToolCallback[] toolCallbacks;

    /**
     * 异步的ai心理咨询咨询
     * @param message 用户提问
     * @param chatId 会话id
     * @return ai回复
     */
    @Operation(description = "异步的ai心理咨询咨询")
    @GetMapping(value = "/chat/sse", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> chatWithSSE(String message, String chatId) {
        return psychologicalConsultationApp.doChatWithSSE(message, chatId);
    }

    /**
     * 使用通用工作智能体
     * @param message 用户提问
     * @return ai回复
     */
    @Operation(description = "使用通用的工作智能体")
    @GetMapping(value = "/chat/manus")
    public SseEmitter chatWithLoveManus(String message) {
        Manus manus = new Manus(chatModel, toolCallbacks);
        return manus.runWithSSE(message);
    }

}
